<?php

namespace app\admin\model;

use think\Model;
use think\Request;

class Geosci extends Model
{

    

    

    // 表名
    protected $name = 'geosci';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        // 'status_text'
        'image'
    ];
    

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getImageAttr($value, $data)
    {
        $value = $value ? $value : $data['image'];
        $domain = Request()->domain();
        return cdnurl($value,$domain);
    }

    public static function list($para,$uid)
    {
        $page = $para['page'] ?? 1;
        $limit = $para['limit'] ?? 10;
        $where['status'] = 1;
        $log = GeosciLog::field('times,geo_id')
                // ->group('geo_id')
                ->where('user_id',$uid)
                ->buildSql();
        $list = self::alias('m')
                    ->field("id,times,title,image,content")
                    ->join([$log => 'log'], 'm.id = log.geo_id','left')
                    ->where($where)
                    ->order('times asc,id desc')
                    ->paginate()->toArray();
        return $list;
    }



}
